<template>
  <!-- 底部部分 => list有数据的时候，才展示  list.length > 0 -->
  <footer v-if="list.length>0" class="footer">
    <span class="todo-count"><strong>{{leftCounts}}</strong>剩余</span>
    <ul class="filters">
      <li>
        <a @click="fliter('all')" :class="{selected:type==='all'}" href="#/">全部</a>
      </li>
      <li>
        <a @click="fliter('active')" :class="{selected:type==='active'}" href="#/active">进行中</a>
      </li>
      <li>
        <a @click="fliter('completed')" :class="{selected:type==='completed'}" href="#/completed">已完成</a>
      </li>
    </ul>
    <!-- 有已完成的任务，才需要显示这个按钮 -->
    <button v-if="isShowClear" @click="clear" class="clear-completed">清除已完成</button>
  </footer>
</template>

<script>
export default {
  data(){
    return {
      
    }
  },
  props:{
    list:{
      type:Array,
      require: true
    },
    type:{
      type:String,
      require: true
    }
  },
  computed:{
    leftCounts(){
      return this.list.filter(item=>item.done===false).length
    },
    isShowClear(){
      return this.list.some(item=>item.done===true)
    }
  },
  methods:{
    clear(){
      this.$emit('clear')
    },
    fliter(type){
      this.$emit('changeType',type)
    }
  }
  
}
</script>

<style></style>
